/**
 * 
 */   
package com.cares.infobird.service;  

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.cares.core.base.service.BaseService;
import com.cares.entity.base.PageModel;
import com.cares.entity.infobird.NoticeInfo;
import com.cares.infobird.repository.NoticeInfoMybatisDao;

/**   
 * @作者 Stone
 * @创建日期 2014-8-16 下午1:59:20
 * @版本 V1.0
 * @类说明
 */
@Service("noticeInfoService")
@Transactional(readOnly = true)
public class NoticeInfoService extends BaseService{
	
	@Autowired
	private NoticeInfoMybatisDao noticeInfoMybatisDao;
	
	/**
	 * 查询列表信息
	 * @param pageModel
	 * @return
	 */
	public String list(PageModel<NoticeInfo> pageModel) {

		String result = "";
		JSONObject json = new JSONObject();
		List<NoticeInfo> results = noticeInfoMybatisDao.getAll(pageModel);
		try {
			json.put("total", this.noticeInfoMybatisDao.count(pageModel));
			json.put("rows", JSON.toJSON(results));
			result = json.toString();
		} catch (JSONException e) {
		}
		return result;
	}
	
	/**
	 * 获取待发送通知信息
	 * @return
	 */
	public List<NoticeInfo> getNoticeList() {
		return noticeInfoMybatisDao.getNoticeList();
	}
	
	/**
	 * 根据ID查询NoticeInfo
	 */
	public NoticeInfo get(Long id) {
		return noticeInfoMybatisDao.get(id);
	}
	
	
	/**
	 * 新增NoticeInfo
	 */
	public void save(NoticeInfo info) {
		info.setOperDtm(dateProvider.getDate());
		noticeInfoMybatisDao.save(info);
	}
	
	/**
	 * 更新NoticeInfo
	 */
	public void update(NoticeInfo info) {
		Assert.notNull(info.getId(), "缺少主键");
		noticeInfoMybatisDao.update(info);
	}
	
	/**
	 * 根据ID删除NoticeInfo
	 */
	public void delete(Long id) {
		noticeInfoMybatisDao.delete(id);
	}
}
